﻿/// <reference path="../libs/typedMVVM/include/typedMVVM.ts" />
/// <reference path="../libs/typedMVVM/include/win.ts" />
var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var TypedMVVM;
(function (TypedMVVM) {
    (function (Samples) {
        /// <reference path="../interfaces/IHomeViewModel.ts" />
        /// <reference path="../interfaces/ISampleService.ts" />
        /// <reference path="../interfaces/ISampleListViewItemModel.ts" />
        (function (ViewModels) {
            // ViewModel for the Home page
            var HomeViewModel = (function (_super) {
                __extends(HomeViewModel, _super);
                // Default constructor
                function HomeViewModel(sampleService) {
                    _super.call(this);

                    this._dataService = sampleService;

                    this.initialiseCommands();
                }
                // Initialise all the commands for the ViewModel
                HomeViewModel.prototype.initialiseCommands = function () {
                    var _this = this;
                    this.initialiseShowMessageDialogCommand();

                    //Initialise all other commands here
                    this.showMessageDialogCommandBind = WinJS.Utilities.markSupportedForProcessing((function () {
                        _this._showMessageDialogCommand.execute("You have just executed a TypedMVVM Command");
                    }).bind(this));

                    this.listItemInvokedBind = WinJS.Utilities.markSupportedForProcessing((function () {
                        _this._showMessageDialogCommand.execute("ListView Item invoked");
                    }).bind(this));
                };

                // Initialise methods and binding for the sample command
                HomeViewModel.prototype.initialiseShowMessageDialogCommand = function () {
                    var _this = this;
                    this._showMessageDialogCommand = new TypedMVVM.Common.Commands.RelayCommand(function (par) {
                        _this.dialogService.showDialog(par);
                    }, function (par) {
                        return par && par != "";
                    });
                };

                // Setup the Data Context for data binding
                HomeViewModel.prototype.setupDataContext = function () {
                    this.dataContext = WinJS.Binding.as({
                        pageTitle: this.pageTitle,
                        sampleText: this.sampleText,
                        commandButtonText: this.commandButtonText,
                        itemsSource: this.itemsSource
                    });
                };

                // Initialise data from the services
                HomeViewModel.prototype.loadData = function () {
                    this.pageTitle = this._dataService.getTitle();
                    this.sampleText = this._dataService.getContent();
                    this.commandButtonText = this._dataService.getCommandButtonText();
                    this.itemsSource = new WinJS.Binding.List(this._dataService.getItemsList(this.dialogService)).dataSource;
                };

                Object.defineProperty(HomeViewModel.prototype, "pageTitle", {
                    // Gets or sets a value for the "pageTitle" property
                    get: function () {
                        return this._pageTitle;
                    },
                    set: function (value) {
                        this._pageTitle = value;
                        this.raisePropertyChanged("pageTitle", value);
                    },
                    enumerable: true,
                    configurable: true
                });

                Object.defineProperty(HomeViewModel.prototype, "sampleText", {
                    // Gets or sets a value for the "sampleText" property
                    get: function () {
                        return this._sampleText;
                    },
                    set: function (value) {
                        this._sampleText = value;
                        this.raisePropertyChanged("sampleText", value);
                    },
                    enumerable: true,
                    configurable: true
                });

                Object.defineProperty(HomeViewModel.prototype, "commandButtonText", {
                    // Gets or sets a value for the "commandButtonText" property
                    get: function () {
                        return this._commandButtonText;
                    },
                    set: function (value) {
                        this._commandButtonText = value;
                        this.raisePropertyChanged("commandButtonText", value);
                    },
                    enumerable: true,
                    configurable: true
                });

                Object.defineProperty(HomeViewModel.prototype, "itemsSource", {
                    // Gets or sets a value for the "sampleText" property
                    get: function () {
                        return this._itemsSource;
                    },
                    set: function (value) {
                        this._itemsSource = value;
                        this.raisePropertyChanged("itemsSource", value);
                    },
                    enumerable: true,
                    configurable: true
                });
                return HomeViewModel;
            })(TypedMVVM.Common.ViewModels.ViewModelBase);
            ViewModels.HomeViewModel = HomeViewModel;
        })(Samples.ViewModels || (Samples.ViewModels = {}));
        var ViewModels = Samples.ViewModels;
    })(TypedMVVM.Samples || (TypedMVVM.Samples = {}));
    var Samples = TypedMVVM.Samples;
})(TypedMVVM || (TypedMVVM = {}));
//# sourceMappingURL=HomeViewModel.js.map
